package sg.edu.nus.iss.vmcs.store;

import java.io.IOException;

import sg.edu.nus.iss.vmcs.system.Environment;

import sg.edu.nus.iss.vmcs.system.CashPropertyLoader;

public class CashStoreCreator extends StoreCreator{
	private CashStore cStore;
	private PropertyLoader cashLoader;
	
	public CashStoreCreator(){
		PropertyLoader defaultLoader=new CashPropertyLoader(Environment.CASH_PROP_FILE);
		this.cashLoader=defaultLoader;
	}
	
	public CashStoreCreator(PropertyLoader cashLoader){
		this.cashLoader=cashLoader;		
	}
	
	public CashStore createStore()
	{		
		
			cStore=CashStore.getInstance();
			try {
				this.initializeCashStore();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return cStore;
		
	}
	
	private void initializeCashStore() throws IOException {
		// get the cash file from the environment property file;
		int numOfItems = cashLoader.getNumOfItems();
		cStore.setStoreSize(numOfItems);

		for (int i = 0; i < numOfItems; i++) {
		    CashStoreItem item = (CashStoreItem) cashLoader.getItem(i);
			cStore.addItem(i, item);
		}
	}
}
